package service.Impl;

import Utils.ConstantUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import dao.users.SysUserDao;
import entity.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import service.SysUserService;

import javax.annotation.Resource;

/**
 * 用户基础信息(SysUser)表服务实现类
 *
 * @author liujh
 * @since 2020-08-10 16:58:53
 */
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
    @Resource
    private SysUserDao sysUserDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysUser queryById(Long id) {
        return this.sysUserDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param pageNum,pageSize
     * @return 对象列表
     */
    @Override
    public Object queryAllByLimit(int pageNum,int pageSize,Model m) {
        Page page = new Page(pageNum,pageSize);
        Page sysUserPage = this.sysUserDao.selectPage(page,null);
        m.addAttribute("dataPage", sysUserPage);
        m.addAttribute("path", ConstantUtils.MENU_JUMP_HREF_USER);
        return m;
    }

    /**
     * 新增数据
     *
     * @param sysUser 实例对象
     * @return 实例对象
     */
    @Override
    public SysUser insert(SysUser sysUser) {
        this.sysUserDao.insert(sysUser);
        return sysUser;
    }

    /**
     * 修改数据
     *
     * @param sysUser 实例对象
     * @return 实例对象
     */
    @Override
    public SysUser update(SysUser sysUser) {
        this.sysUserDao.update(sysUser);
        return this.queryById(sysUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.sysUserDao.deleteById(id) > 0;
    }

    @Override
    public SysUser queryByName(String username) {
        return this.sysUserDao.queryByName(username);
    }
}